import Vue from "vue";
import VueRouter from "vue-router";

// 解决连续点击同一个路由出bug
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this,to).catch(err => err)
}

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/reg",
    name: "reg",
    component: () => import('../views/Reg'),
    meta: {
      title: "注册页"
    }
  },
  {
    path: "/login",
    name: "login",
    component: () => import('../views/Login'),
    meta: {
      title: "登录页"
    }
  },
  {
    path: "/home",
    name: "home",
    component: () => import('../views/Home'),
    redirect: "/home/user",
    meta: {
      title: "主页"
    },
    children: [
      {
        path: "user",
        name: "user",
        component: () => import('../views/Users'),
        meta: {
          title: "用户管理"
        }
      },
      {
        path: "goods",
        name: "goods",
        component: () => import('../views/Goods'),
        meta: {
          title: "商品管理"
        }
      },
      {
        path: "order",
        name: "order",
        component: () => import('../views/Orders'),
        meta: {
          title: "订单管理"
        }
      },
      {
        path: "comment",
        name: "comment",
        component: () => import('../views/Comments'),
        meta: {
          title: "评论管理"
        }
      },
    ]
  },
  // {
  //   path: "/about",
  //   name: "About",
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () =>
  //     import(/* webpackChunkName: "about" */ "../views/About.vue")
  // }
];

const router = new VueRouter({
  routes
});

export default router;